package net.labdemo.common.util;

/**
 * Page类的助手类
 * @author xiaofanku
 * 20160128
 */
public class PageHelper {
	//总记录数
	private final int total;
	//现在是第几页
	private final int page;
	//一页要显示的记录数
	private final int pageSize;
	//计算有几页
	private int totalPage=0;
	
	public PageHelper(final int page,final int pageSize,final int total){
		this.total=total;
		this.page=page;
		this.pageSize=pageSize;
		if(total>0){
			calcTotalPage();
		}
	}
	
	private void calcTotalPage(){
		int total_page=0;
		//不足一页
		if(total>0){
			if(pageSize>=total){
				total_page=1;
			}
			if(pageSize<total){
				//整除
				total_page=total / pageSize;
				//不整除
				double a=total % pageSize;
				if(a != 0){
					total_page+=1;
				}
			}
		}
		this.totalPage=total_page;
	}
	//是否有下一页
	public boolean hasNext(){
		//pageTotal=page
		//pageTotal>page
		//pageTotal<page[x]
		return this.totalPage>this.page?true:false;
	}
	//是否有上一页
	public boolean hasPrev(){
		if(page<=1){
			return false;
		}
		return true;
	}
	public int getTotalPage(){
		return this.totalPage;
	}
	//覆盖
	public void setTotalPage(int showMaxPage){
		this.totalPage=showMaxPage;
	}
	public int getPage() {
		return page;
	}

	public int getTotal() {
		return total;
	}
}
